//
//  CZMeVC.m
//  CZWeiXin
//
//  Created by Alvechen on 16/4/13.
//  Copyright © 2016年 alvechen. All rights reserved.
//

#import "CZMeVC.h"
#import "JHChangePasswordVC.h"

@interface CZMeVC ()
@property (weak, nonatomic) IBOutlet UIImageView *avatarImgV;

@property (weak, nonatomic) IBOutlet UILabel *nickNameLb;
@property (weak, nonatomic) IBOutlet UILabel *acountLb;

///我的资料卡
@property (nonatomic,strong) XMPPvCardTemp  *myvCardTemp;

@end

@implementation CZMeVC

- (XMPPvCardTemp *)myvCardTemp{
    
    return [CZXMPPManager shareInstance].xmppvCardTempModule.myvCardTemp;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    //分组头尾视图高度
    self.tableView.sectionFooterHeight = 10;
    self.tableView.sectionHeaderHeight = 10;
    
    //
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 20)];
    self.tableView.tableHeaderView = headerView;
    
    
    //设置个人资料模块代理
    [[CZXMPPManager shareInstance].xmppvCardTempModule addDelegate:self delegateQueue:dispatch_get_main_queue()];
    
    //更新UI
    [self updateUI];
    
}

/**
 * 更新UI
 */
- (void)updateUI{

    //头像
    self.avatarImgV.image = [UIImage imageWithData:self.myvCardTemp.photo];
    //昵称
    self.nickNameLb.text = self.myvCardTemp.nickname;
    //账号
//    self.acountLb.text = self.myvCardTemp.jid.bare;//这个bare里没值
    self.acountLb.text = kCZ_myJID.bare;
}

#pragma mark - UI事件

- (IBAction)revisePassword:(id)sender {
    
    NSLog(@"修改密码");
    
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"ChangePassword" bundle:nil];
    
    JHChangePasswordVC *changeVC = [sb instantiateInitialViewController];
    
    [self presentViewController:changeVC animated:YES completion:nil];
}


#pragma mark - XMPPvCardTempModuleDelegate

/**
 * 更新我的资料卡成功
 */
- (void)xmppvCardTempModuleDidUpdateMyvCard:(XMPPvCardTempModule *)vCardTempModule{
    
    //更新UI
    [self updateUI];
}


@end
